package org.eclipse.milo.examples.server.config;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;


public class ConfigManager {
    private static final Logger LOG = LoggerFactory.getLogger(ConfigManager.class);

    // 配置文件的URL环境变量名
    private static final String ConfigUrl = "DATA_MAKER_CONF_URL";
    private static Config conf = null;
    private static final Object lock = new Object();
    private static boolean initialized = false;

    public static boolean init() {
        if (!initialized) {
            synchronized (lock) {
                if (!initialized) {
                    conf = ConfigFactory.parseFile(new File("conf" + File.separator + "application.conf"));
                    //conf = ConfigFactory.load();
                    initialized = true;
                    return true;
                }
            }
        }
        return true;
    }

	public static Config getConfig() {
		if (!initialized) {
		    LOG.error("ConfigReader not initialized. Please call init first!!!");
			throw new RuntimeException("ConfigReader not initialized. Please call init first!!!");
		}
		return conf;
	}
}